﻿#ifndef GLOBALHOOKS_H
#define GLOBALHOOKS_H

#include <QObject>
#include<Windows.h>
#include<QMutex>
class GlobalHooks : public QObject
{
    Q_OBJECT
public:
    static GlobalHooks*& getinstance();
signals:
    void keyPressed(WPARAM wParam, LPARAM lParam);
    void keyReleased(WPARAM wParam, LPARAM lParam);
    void mouseLeftButtonPressed(WPARAM wParam, LPARAM lParam);
    void mouseRightButtonPressed(WPARAM wParam, LPARAM lParam);
    void mouseLeftButtonReleased(WPARAM wParam, LPARAM lParam);
    void mouseRightButtonReleased(WPARAM wParam, LPARAM lParam);
private slots:
    static LRESULT lowLevelKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam);
    static LRESULT lowLevelMouseProc(int nCode, WPARAM wParam, LPARAM lParam);
private:
    HHOOK keyboardHook_;
    HHOOK mouseHook_;
    static GlobalHooks* instance;
    static QMutex instanceMutex;
    explicit GlobalHooks(QObject *parent = nullptr);
    ~GlobalHooks();
    GlobalHooks(const GlobalHooks&)=delete;
    GlobalHooks& operator=(const GlobalHooks&)=delete;
    class Deleter
    {
    public:
        Deleter(QMutex& Mutex);
        ~Deleter();
    private:
        QMutex& deleterMutex;
    };
    static Deleter deleter;
};

#endif // GLOBALHOOKS_H
